import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:yuan_hang_app/bean/user.dart';
import 'package:yuan_hang_app/res/w_colors.dart';
import 'package:yuan_hang_app/res/w_dimens.dart';
import 'package:yuan_hang_app/utils/string_utils.dart';
import 'package:yuan_hang_app/widget/w_dialog.dart';
import 'package:yuan_hang_app/widget/w_text.dart';

import '../utils/size_utils.dart';

class CommonDialog {
  static void showEWDialog({
    context,
    url,
  }) {
    showDialog(
        context: context,
        builder: (c) => Scaffold(
              resizeToAvoidBottomInset: true,
              backgroundColor: Colors.transparent,
              body: Center(
                child: Container(
                  width: SizeUtils.screenW() * 0.8,
                  height: SizeUtils.screenW() * 0.8,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(5.px),
                  ),
                  child: Material(
                    type: MaterialType.transparency,
                    child: SizedBox(
                      width: SizeUtils.screenW() * 0.8,
                      height: SizeUtils.screenW() * 0.8,
                      //   alignment: Alignment.center,
                      child: Stack(
                        children: [
                          Center(
                            child: QrImageView(
                              data: url,
                              version: QrVersions.auto,
                              size: SizeUtils.screenW() * 0.64,
                            ),
                          ),
                          Positioned(
                            right: 10.px,
                            top: 10.px,
                            child: GestureDetector(
                              onTap: () {
                                ///    print("==========dian=======$url");
                                Navigator.pop(context);
                              },
                              child: Image.asset(
                                "images/ic_del.png",
                                width: 25.px,
                                color: WColors.hintTextColor,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ));
  }

  static void showCardDialog({context, url, required User userInfo}) {
    showDialog(
        context: context,
        builder: (c) => Scaffold(
              resizeToAvoidBottomInset: true,
              backgroundColor: Colors.transparent,
              body: Center(
                child: Container(
                  width: SizeUtils.screenW() * 0.8,
                  height: SizeUtils.screenW() * 1.1,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(5.px),
                  ),
                  child: Material(
                    type: MaterialType.transparency,
                    child: SizedBox(
                      //    padding: EdgeInsets.symmetric(vertical: 20.px),
                      width: SizeUtils.screenW() * 0.8,
                      height: SizeUtils.screenW() * 1.1,

                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            padding: EdgeInsets.only(right: 10.px, top: 10.px),
                            alignment: Alignment.topRight,
                            child: GestureDetector(
                              onTap: () {
                                ///    print("==========dian=======$url");
                                Navigator.pop(context);
                              },
                              child: Image.asset(
                                "images/ic_del.png",
                                width: 25.px,
                                color: WColors.hintTextColor,
                              ),
                            ),
                          ),
                          SizedBox(
                            height: 10.px,
                          ),
                          WText(
                            StringUtils.safeGetValue(userInfo.employeeName),
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                color: WColors.mainTextColor,
                                fontSize: WDimens.tsXLarge),
                          ),
                          SizedBox(
                            height: 10.px,
                          ),
                          WText(
                            "${StringUtils.safeGetValue(userInfo.shopName)} ${StringUtils.safeGetValue(userInfo.roleName)}",
                            style: TextStyle(
                                color: WColors.subTextColor,
                                fontSize: WDimens.tsLarge),
                          ),
                          SizedBox(
                            height: 10.px,
                          ),
                          WText(
                              "手机号：${StringUtils.safeGetValue(userInfo.mobilePhone, placeHolder: "-")}",
                              style: TextStyle(
                                  color: WColors.subTextColor,
                                  fontSize: WDimens.tsLarge)),
                          SizedBox(
                            height: 10.px,
                          ),
                          Stack(
                            alignment: Alignment.center,
                            children: [
                              Center(
                                child: QrImageView(
                                  data: url,
                                  version: QrVersions.auto,
                                  size: SizeUtils.screenW() * 0.6,
                                ),
                              ),
                              Center(
                                child: ClipRRect(
                                  borderRadius: BorderRadius.circular(5.px),
                                  child: StringUtils.safeGetValue(
                                              userInfo.headPortrait) ==
                                          ""
                                      ? Image.asset(
                                          "images/head.png",
                                          width: 48.px,
                                          height: 48.px,
                                          fit: BoxFit.cover,
                                        )
                                      : Image.network(
                                          userInfo.headPortrait!,
                                          width: 48.px,
                                          height: 48.px,
                                          fit: BoxFit.cover,
                                        ),
                                ),
                              )
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ));
  }

  static void showConformDialog(
      {context,
      title = "提示",
      content,
      other,
      onConfirm,
      onCancel,
      cancelTitle = "取消",
      confirmTitle = "确定",
      hintText = "请填写...",
      confirmColor,
      cancelHide = false,
      maxLength = -1,
      inputType = InputType.PHONE,
      textInputFormatter,
      type = DGTheme.normal}) {
    showDialog(
        context: context,
        builder: (c) => WDialog(c,
            title: title,
            content: content,
            onCancel: onCancel,
            other: other,
            cancelTitle: cancelTitle,
            confirmTitle: confirmTitle,
            confirmColor: confirmColor,
            cancelHide: cancelHide,
            maxLength: maxLength,
            inputType: inputType,
            textInputFormatter: textInputFormatter,
            type: type,
            onConfirm: onConfirm));
  }
}
